package com.gang.utils;



import com.spire.pdf.PdfDocument;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPage;
import org.apache.pdfbox.text.PDFTextStripper;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
import org.apache.poi.xwpf.usermodel.XWPFRun;

import java.io.File;
import java.io.FileInputStream;
import java.util.List;

public class GetWater {
    public static String get(String path) throws Exception {

        File file = new File(path);
        String text="";
        try {
            //加载pdf文件，创建PDDocument对象
            PDDocument document = PDDocument.load(file);
            new PdfDocument();
            //创建pdf文本获取对象PDFTextStripper
            PDFTextStripper pdfStripper = new PDFTextStripper();
            String lineSeparator = pdfStripper.getLineSeparator();
            PDPage pdPage = document.getPages().get(0);

            //获取pdf中所有信息，text中包含的就是当前pdf文档中所有信息
            text = pdfStripper.getText(document);
            int i = text.lastIndexOf('#');
            text=text.substring(i+1,text.length());
            System.out.println(text);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return text;
    }
}
